package com.qf.config;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//定义的拦截器
public class MyInterceptor implements HandlerInterceptor {


    //执行控制器放之前先执行
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {
        System.out.println("执行控制器方法之前,preHandle执行了");
        return true;
    }

    //执行控制器方法之后执行
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("执行控制器方法之后,postHandle执行了");
    }

    //视图渲染完成, 控制器中return 的时候,展示视图
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("渲染视图完成...");
    }
}
